package com.naizhuai.ui.rank;


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.naizhuai.R;
import com.naizhuai.ui.rank.multType.ActionDistribute;
import com.naizhuai.ui.rank.multType.ActionDistributeViewBinder;
import com.naizhuai.ui.rank.multType.OrganizeActive;
import com.naizhuai.ui.rank.multType.OrganizeActiveViewBinder;
import com.naizhuai.ui.rank.multType.OrganizeChart;
import com.naizhuai.ui.rank.multType.OrganizeChartViewBinder;
import com.naizhuai.ui.task.multtype.LineItem;
import com.naizhuai.ui.task.multtype.LineViewBinder;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import me.drakeet.multitype.Items;
import me.drakeet.multitype.MultiTypeAdapter;

/**
 * A simple {@link Fragment} subclass.
 */
public class OrganizeFragment extends Fragment {
    @BindView(R.id.organizeContainer)
    RecyclerView organizeContainer;
    Unbinder unbinder;
    MultiTypeAdapter mTypeAdapter;
    Items mItems;

    public static OrganizeFragment newInstance() {
        OrganizeFragment fragment = new OrganizeFragment();
        return fragment;
    }

    public OrganizeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_organize, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mTypeAdapter=new MultiTypeAdapter();
        mItems=new Items();

        mTypeAdapter.register(OrganizeActive.class,new OrganizeActiveViewBinder());
        mTypeAdapter.register(ActionDistribute.class,new ActionDistributeViewBinder());
        mTypeAdapter.register(OrganizeChart.class,new OrganizeChartViewBinder());
        mTypeAdapter.register(LineItem.class,new LineViewBinder());

        mItems.add(new LineItem());
        mItems.add(new OrganizeActive());
        mItems.add(new LineItem());
        mItems.add(new ActionDistribute());
        mItems.add(new LineItem());
        mItems.add(new OrganizeChart("行动总数","324个"));
        mItems.add(new LineItem());
        mItems.add(new OrganizeChart("任务总数","62个"));
        mItems.add(new LineItem());
        mItems.add(new OrganizeChart("参与人次","322人"));
        mItems.add(new LineItem());
        mItems.add(new OrganizeChart("模拟效果合计","32万"));
        mTypeAdapter.setItems(mItems);
        organizeContainer.setLayoutManager(new LinearLayoutManager(getActivity()));
        organizeContainer.setAdapter(mTypeAdapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
